package com.nhy.bloggers.service;

import com.nhy.bloggers.entity.Blog;
import com.nhy.bloggers.entity.User;
import com.nhy.bloggers.mapper.BlogMapper;
import com.nhy.bloggers.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    @Autowired
    private BlogMapper blogMapper;

    public User getUserInfo(String username){
        return userMapper.selectByName(username);
    }

    public User getUserInfoByBlogId(Integer blogId){
        User user = null;
        Blog blog = blogMapper.selectById(blogId);
        if (blog!=null && blog.getUserId()>0){
            user = userMapper.selectById(blog.getUserId());
            return user;
        }
        return null;
    }

}
